package com.xbongbong.pro.statistic.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * @author 梁鲁江
 * @version v1.0
 * @date 2019/3/25 14:46
 * @since v1.0
 */
@Getter
public enum FormLocationEnum {
    /**
     * 表单的位置
     */
    A(1,"at","enum.formLocation.msg.a","A"),
    B(2,"bt","enum.formLocation.msg.b","B"),
    C(3,"ct","enum.formLocation.msg.c","C"),
    D(4,"dt","enum.formLocation.msg.d","D"),
    E(5,"et","enum.formLocation.msg.e","E"),
    F(6,"ft","enum.formLocation.msg.f","F"),
    ;
    /**
     * 枚举值
     */
    private final int code;
    /**
     * 位置
     */
    private final String location;
    /**
     * 中文描述
     */
    private final String msg;
    
    private final String tableAlias;

    FormLocationEnum(int code, String location, String msg,String tableAlias) {
        this.code = code;
        this.location = location;
        this.msg = msg;
        this.tableAlias = tableAlias;
    }

    /**
     * 根据code获取枚举
     * @param code
     * @return
     */
    public static FormLocationEnum getByCode(Integer code) {
        for (FormLocationEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return null;
    }
    public static FormLocationEnum getByTableAlias(String tableAlias) {
        for (FormLocationEnum cacheCode : values()) {
            if(Objects.equals(tableAlias,cacheCode.getTableAlias())){
                return cacheCode;
            }
        }
        return null;
    }
    public String getMsg() {
        return I18nMessageUtil.getMessage(msg);
    }
}
